package com.aizuda.boot.modules.business.approval.controller;

import com.aizuda.boot.modules.business.approval.entity.dto.HandoverDTO;
import com.aizuda.boot.modules.business.approval.entity.dto.QueryHandoverDTO;
import com.aizuda.boot.modules.business.approval.entity.dto.QueryHandoverHistoryDTO;
import com.aizuda.boot.modules.business.approval.entity.vo.HandoverHistoryVO;
import com.aizuda.boot.modules.business.approval.entity.vo.HandoverQueryVO;
import com.aizuda.boot.modules.business.approval.service.HandoverService;
import com.aizuda.boot.modules.business.contract.dto.SingleResponse;
import com.aizuda.boot.modules.common.constant.enums.ResponseCodeEnum;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author sangyirong
 * @ClassName HandoverController
 * @Version 1.0
 * @Date 2025/7/24 17:21
 */
@Slf4j
@RestController
@RequestMapping("/handover")
@Tag(name = "审批交接")
public class HandoverController {

    @Resource
    private HandoverService handoverService;

    @Operation(summary = "获取交接历史")
    @PostMapping("/list")
    public SingleResponse<IPage<HandoverHistoryVO>> history(@RequestBody QueryHandoverHistoryDTO dto){
        try {
            return handoverService.history(dto);
        }catch (Exception e){
            log.error("获取交接历史失败:", e);
            return SingleResponse.failure(ResponseCodeEnum.SYS_ERROR.getCode(), ResponseCodeEnum.SYS_ERROR.getMsg());
        }
    }

    @Operation(summary = "查询审批交接列表")
    @PostMapping("query")
    public SingleResponse<List<HandoverQueryVO>> query(@RequestBody QueryHandoverDTO dto) {
        try {
            return handoverService.query(dto);
        } catch (Exception e) {
            log.error("查询审批交接列表失败", e);
            return SingleResponse.failure(ResponseCodeEnum.SYS_ERROR.getCode(), ResponseCodeEnum.SYS_ERROR.getMsg());
        }
    }

    @Operation(summary = "交接")
    @PostMapping
    public SingleResponse handover(@RequestBody HandoverDTO dto){
        try {
            return handoverService.handover(dto);
        }catch (Exception e){
            log.error("审批交接失败", e);
            return SingleResponse.failure(ResponseCodeEnum.SYS_ERROR.getCode(), ResponseCodeEnum.SYS_ERROR.getMsg());
        }
    }

}
